home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Annotations / Append Calibrator < prev    next >
Text File  |  1994-02-18  |  4KB  |  115 lines

  1. #include <Strings as Lists>
  2. #include <Axis Utilities>
  3.  
  4. Function InitCalibratorGlobals()
  5.     String/G u_xaxis="bottom",u_yaxis="left"
  6.     Variable/G/D u_dx=1,u_dy=1
  7.     Variable/G u_orient=1,u_label=1    | upper-left, print
  8. End
  9.  
  10. Macro Calibrator(xaxis,yaxis,dx,dy,orient,label)
  11.     String xaxis=u_xaxis,yaxis=u_yaxis
  12.     Variable/D dx=u_dx,dy=u_dy
  13.     Variable orient=u_orient,label=u_label
  14.     Prompt xaxis,"X axis (horizontal axis)",popup,HVAxisList("",1)    |  only horizontal axes
  15.     Prompt yaxis,"Y axis (vertical axis)",popup,HVAxisList("",0)    |  only vertical axes
  16.     Prompt dx,"calibrator X length, or 0 for none"
  17.     Prompt dy,"calibrator Y length, or 0 for none"
  18.     Prompt orient,"Orientation",popup,"upper-left;upper-right;lower-right;lower left;"
  19.     Prompt label,"print values",popup,"don’t print;print;print with units;print with units and ,K,m,µ etc"
  20.     
  21.     PauseUpdate;Silent 1
  22.     u_xaxis=xaxis;u_yaxis=yaxis
  23.     u_dx=dx;u_dy=dy
  24.     u_orient=orient;u_label=label
  25.     
  26.     FCalibrator(xaxis,yaxis,dx,dy,orient,label)
  27. End
  28.  
  29. | Replace "Function" with "Macro" to reduce compile time
  30. Function FCalibrator(xaxis,yaxis,dx,dy,orient,label)
  31.     String xaxis,yaxis
  32.     Variable/D dx,dy
  33.     Variable orient,label    | see popup list of Calibrator macro for label values (1 is don't print, etc)
  34.     
  35.     | Put calibrator in upper right corner of graph
  36.     Variable/D xorig,yorig    | corner of calibrator
  37.     Variable/D px,py        | polygon origin
  38.     Variable/D hx,hy,vx,vy    | text origins
  39.     Variable/D sf=0.15        | inset from upper-right corner
  40.     GetAxis/Q $xaxis;xorig=V_max-(V_max-V_min)*sf
  41.     GetAxis/Q $yaxis;yorig=V_max-(V_max-V_min)*sf
  42.  
  43.     GraphNormal            | Forces deselection
  44.     SetDrawEnv gstart        | gstart can't be on next line!
  45.     SetDrawEnv xcoord= $xaxis,ycoord= $yaxis, fillpat=0,linethick=3
  46.     if(orient == 1) | upper-left
  47.         xorig -= dx
  48.         hx= xorig + dx/2
  49.         vy= yorig - dy/2
  50.         px= xorig;py=yorig-dy
  51.         DrawPoly px,py, 1, 1, {0,0,0,dy,dx,dy}
  52.     endif
  53.     if(orient == 2) | upper-right
  54.         hx= xorig - dx/2
  55.         vy= yorig - dy/2
  56.         px= xorig-dx;py=yorig
  57.         DrawPoly px,py, 1, 1, {0,0,dx,0,dx,-dy}
  58.     endif
  59.     if(orient == 3) | lower-right
  60.         yorig -= dy
  61.         hx= xorig - dx/2
  62.         vy= yorig + dy/2
  63.         px= xorig;py=yorig+dy
  64.         DrawPoly px,py, 1, 1, {0,0,0,-dy,-dx,-dy}
  65.     endif
  66.     if(orient == 4) | lower left
  67.         xorig -= dx
  68.         yorig -= dy
  69.         hx= xorig + dx/2
  70.         vy= yorig + dy/2
  71.         px= xorig+dx;py=yorig
  72.         DrawPoly px,py, 1, 1, {0,0,-dx,0,-dx,dy}
  73.     endif
  74.     String labelVal,fmt,units
  75.     | horizontal calibrator value
  76.     if( (dx != 0)%& (label>1) )        | label == 1 is don't print
  77.         units= AxisUnits(xaxis)
  78.         fmt="%g"
  79.         if( (label== 3) %& (strlen(units)>0) )    | 3 is print with units
  80.             fmt += " "+units
  81.         endif
  82.         if(label == 4)                | 4 is print with units and prefixes
  83.             fmt="%.1W1P"+units    | change %.1 to number of digits after decimal point you want (%.2 is two digits, etc)
  84.         endif
  85.         sprintf labelVal, fmt, dx
  86.         hy = yorig
  87.         Variable yj=0    | bottom
  88.         if( orient >= 3 )
  89.             yj= 2        | top
  90.         endif
  91.         SetDrawEnv xcoord= $xaxis,ycoord= $yaxis,textxjust= 1,textyjust=yj
  92.         DrawText hx,hy, labelVal
  93.     endif
  94.     | vertical calibrator value
  95.     if( (dy != 0)%& (label>1) )
  96.         units= AxisUnits(yaxis)
  97.         fmt="%g"
  98.         if( (label== 3) %& (strlen(units)>0) )
  99.             fmt += " "+units
  100.         endif
  101.         if(label == 4)
  102.             fmt="%.1W1P"+units
  103.         endif
  104.         sprintf labelVal, fmt, dy
  105.         vx= xorig
  106.         Variable xj=0,rot=0                    | left    | use rot= -90 for top-to-bottom
  107.         if( (orient == 1) %| (orient == 4) )    |"upper-left; upper-right;lower-right;lower left;"
  108.             xj= 2                                |right use rot=90 for bottom-to-top
  109.         endif
  110.         SetDrawEnv xcoord= $xaxis,ycoord= $yaxis,textxjust= xj,textyjust=1,textrot=rot
  111.         DrawText vx,vy, " "+labelVal+" "    | extra spaces to keep label away from line
  112.     endif
  113.     SetDrawEnv gstop
  114. End
  115.